import { IsEmail, IsString, MinLength, MaxLength, Matches, IsOptional } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'

/**
 * 用户注册数据传输对象
 */
export class RegisterDto {
  @ApiProperty({
    description: '用户名',
    example: 'admin',
    minLength: 3,
    maxLength: 20
  })
  @IsString({ message: '用户名必须是字符串' })
  @MinLength(3, { message: '用户名至少3个字符' })
  @MaxLength(20, { message: '用户名最多20个字符' })
  @Matches(/^[a-zA-Z0-9_]+$/, { message: '用户名只能包含字母、数字和下划线' })
  username: string

  @ApiProperty({
    description: '邮箱地址',
    example: 'admin@example.com'
  })
  @IsEmail({}, { message: '请输入有效的邮箱地址' })
  email: string

  @ApiProperty({
    description: '密码',
    example: 'Password123!',
    minLength: 8,
    maxLength: 50
  })
  @IsString({ message: '密码必须是字符串' })
  @MinLength(8, { message: '密码至少8个字符' })
  @MaxLength(50, { message: '密码最多50个字符' })
  @Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/, {
    message: '密码必须包含大小写字母、数字和特殊字符'
  })
  password: string

  @ApiProperty({
    description: '确认密码',
    example: 'Password123!'
  })
  @IsString({ message: '确认密码必须是字符串' })
  confirmPassword: string

  @ApiProperty({
    description: '昵称',
    example: '管理员',
    required: false
  })
  @IsOptional()
  @IsString({ message: '昵称必须是字符串' })
  @MaxLength(50, { message: '昵称最多50个字符' })
  nickname?: string
}
